﻿using SqlSugar;
using 电驱线暗灯板.Models;

namespace 微信机器人服务.Service
{
    public class DatabaseInitializer
    {
        private readonly ILogger<DatabaseInitializer> _logger;
        private readonly ISqlSugarClient _sqlSugarClient;
        public DatabaseInitializer(ILogger<DatabaseInitializer> logger, ISqlSugarClient sqlSugarClient)
        {
            _logger = logger;
            _sqlSugarClient = sqlSugarClient;
        }
        public void Initialize()
        {
            #region 初始化日志表
            //Job执行日志
            if (!_sqlSugarClient.DbMaintenance.IsAnyTable(LogName.Job执行日志, false))
            {
                _sqlSugarClient.CodeFirst.As<LogData>(LogName.Job执行日志).InitTables<LogData>();
            }
            if (!_sqlSugarClient.DbMaintenance.IsAnyTable(LogName.Api执行日志, false))
            {
                _sqlSugarClient.CodeFirst.As<LogData>(LogName.Api执行日志).InitTables<LogData>();
            }
            if (!_sqlSugarClient.DbMaintenance.IsAnyTable(LogName.控制器操作执行情况, false))
            {
                _sqlSugarClient.CodeFirst.As<LogData>(LogName.控制器操作执行情况).InitTables<LogData>();
            }
            if (!_sqlSugarClient.DbMaintenance.IsAnyTable(LogName.HTTP请求的完成情况, false))
            {
                _sqlSugarClient.CodeFirst.As<LogData>(LogName.HTTP请求的完成情况).InitTables<LogData>();
            }
            //系统日志
            if (!_sqlSugarClient.DbMaintenance.IsAnyTable(LogName.系统日志, false))
            {
                _sqlSugarClient.CodeFirst.As<LogData>(LogName.系统日志).InitTables<LogData>();
            }
            //其它日志
            if (!_sqlSugarClient.DbMaintenance.IsAnyTable(LogName.其它日志, false))
            {
                _sqlSugarClient.CodeFirst.As<LogData>(LogName.其它日志).InitTables<LogData>();
            }
            #endregion
        }
    }
}
